package spr

import (
	pl "db2s/Or/spr/parser"
	"fmt"
	"github.com/antlr4-go/antlr/v4"
	"reflect"
)

func booleanExpressionComparisonSpec(node antlr.RuleNode) {
	for _, child := range node.GetChildren() {
		switch childNode := child.(type) {
		case *antlr.TerminalNodeImpl:
		default:
			fmt.Println("--------default func=singleLogicalExpression():", reflect.TypeOf(childNode), childNode.(antlr.RuleNode).GetText())
		}
	}
}
func singleLogicalExpression(node antlr.RuleNode) {
	for _, child := range node.GetChildren() {
		switch childNode := child.(type) {
		case *antlr.TerminalNodeImpl:
		case *pl.Expression_wrapperContext:
		case *pl.Boolean_expression_exists_specContext:
		case *pl.Op_any_expression_specContext:
		case *pl.Op_all_expression_specContext:
		case *pl.Function_call_expression_specContext:
		case *pl.Subquery_expression_specContext:
		case *pl.Timestamp_expression_specContext:
		case *pl.Boolean_expression_literal_specContext:
		case *pl.Variable_expression_specContext:
		case *pl.Cursor_expression_specContext:
		case *pl.Character_expression_constant_specContext:
		case *pl.Numeric_expression_implicit_cursor_attr_specContext:
		case *pl.Numeric_expression_constant_specContext:
		case *pl.Numeric_expression_specContext:
		case *pl.Boolean_expression_reverse_specContext:
		case *pl.Boolean_expression_null_predicate_specContext:
		case *pl.Boolean_expression_in_range_specContext:
		case *pl.Multi_expression_in_range_specContext:
		case *pl.Boolean_expression_between_range_specContext:
		case *pl.Boolean_expression_implicit_attr_specContext:
		case *pl.Searched_case_expression_specContext:
		case *pl.Simple_case_expression_specContext:
		case *pl.Outer_join_plus_symbol_expression_specContext:
		case *pl.Distinct_expression_specContext:
		case *pl.Interval_expression_specContext:
		case *pl.Date_expression_specContext:
		case *pl.Asterisk_expression_specContext:
		case *pl.Bind_variable_expression_specContext:
		case *pl.Arrow_assignment_expression_specContext:
		case *pl.Using_char_cs_expression_specContext:
		case *pl.Numeric_expression_arithmetic_specContext:
		case *pl.Boolean_expression_comparison_specContext:
			booleanExpressionComparisonSpec(childNode)
		case *pl.Character_expression_association_specContext:
		case *pl.Boolean_expression_like_specContext:
		case *pl.Trigger_conditional_predicatesContext:
		case *pl.Expression_list_specContext:
		default:
			fmt.Println("--------default func=singleLogicalExpression():", reflect.TypeOf(childNode), childNode.(antlr.RuleNode).GetText())
			//singleLogicalExpression(childNode.(antlr.RuleNode))
		}
	}
}
func combinedLogicalExpressionContext(node antlr.RuleNode) {
	for _, child := range node.GetChildren() {
		switch childNode := child.(type) {
		case *antlr.TerminalNodeImpl:
		case *pl.Simple_expressionContext:
			singleLogicalExpression(childNode)
		case *pl.Boolean_logical_operationContext:
		default:
			//fmt.Println("--------default func=combinedLogicalExpressionContext():", reflect.TypeOf(childNode), childNode.(antlr.RuleNode).GetText())
		}
	}
}
func whereClauseContext(node antlr.RuleNode) (res []whereCondition) {
	for _, child := range node.GetChildren() {
		switch childNode := child.(type) {
		case *antlr.TerminalNodeImpl:
		case *pl.Simple_expressionContext: //单个表达式
		case *pl.Combined_logical_expressionContext: //多个关联条件
			combinedLogicalExpressionContext(childNode)
		case *pl.Parenthesized_logical_expressionContext: //(logical_expression)
		case *pl.Prior_logical_expressionContext:
		default:
			fmt.Println("--------default func=whereList():", reflect.TypeOf(childNode), childNode.(antlr.RuleNode).GetText())
			whereClauseContext(childNode.(antlr.RuleNode))
		}
	}
	return
}
